package bueu.bexl;

import static bueu.bexl.utils.TypeUtils.booleanValue;

public class OrExpr extends BinayExpr {
	
	public OrExpr(final BexlExpr expr1, final BexlExpr expr2) {
		super(expr1, expr2);
	}

	@Override
	protected final Object eval(final BexlCtx ctx, final Object current, final boolean set, 
			final Object newValue) throws BexlException {
		Object value1 = getExpr1().eval(ctx, current, set, newValue);
		
		if (booleanValue(value1)) {
			return value1;
		}
		
		Object value2 = getExpr2().eval(ctx, current, set, newValue);
		
		return booleanValue(value2)? value2 : false;
	}

	@Override
	protected final Object evaluate(Object value1, Object value2) {
		return null; // No usada
	}
	
	@Override
	public final String toString() {
		return toString("||");
	}
}
